package youleche.com.common;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Random;

/**
 * ID工厂
 * @author Administrator
 *
 */
public class IDFactory {
	/**
	 * 获取ID
	 * @param databaseName 数据库名
	 * @param tableName  表名
	 * @return 返回ID
	 */
	public static String getId(String databaseName, String tableName){
		Calendar cal = Calendar.getInstance();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		String header = sdf.format(cal.getTime());
		Random random = new Random();
		String rendomStr = "";
		for (int i = 0; i < 10; i++) {
			rendomStr += random.nextInt(9);
		}
		
		String id = header + "-" + rendomStr +  "-" + databaseName +  "-" + tableName +  "-" + "0001";
		if(id.length() > 100){
			id = id.substring(0, 100).toLowerCase();
		}
		
		return header + "-" + rendomStr +  "-" + databaseName +  "-" + tableName +  "-" + "0001"; 
	}
}
